# 写入内容
from openpyxl import load_workbook, Workbook


def read_excel(path, sheet_name):
    wb = load_workbook(path)
    ws = wb[sheet_name]

    data_list = []
    for row in ws.iter_rows(values_only=True):
        data_list.append(row)
    return data_list


data = read_excel("../files/data.xlsx", "Sheet1")

# wb = Workbook() # 新工作簿
# if "Sheet2" in wb:
#     ws = wb["Sheet2"]
# else:
#     ws = wb.create_sheet("Sheet2")
# ws.append(["姓名", "性别", "年龄"])
# wb.save("new_data.xlsx")


# 把data.xlsx中的内容全部写入到新的表格中
wb = Workbook()
if "Sheet2" in wb:
    ws = wb["Sheet2"]
else:
    ws = wb.create_sheet("Sheet2")
for row in data:
    ws.append(row)
wb.save("new_data.xlsx")